//
//  VisitorTableViewController.swift
//  weibo
//
//  Created by huangtuo on 16/6/3.
//  Copyright © 2016年 huangtuo. All rights reserved.
//

import UIKit

class VisitorTableViewController: UITableViewController {
    
    func visitorViewDidLogin() {
        let vc = OAuthViewController()
        let nav = UINavigationController(rootViewController: vc)
        
        presentViewController(nav, animated: true, completion: nil)
    }
    
    func visitorViewDidRegister() {
        print("注册")
    }

    //判断用户是否登陆
    private var isLogin = false
    
    //对外提供visitorview的属性
    var visitorView  : VisitorView?
    
    
    override func loadView() {
        
        isLogin ? super.loadView() : setupVisitorView()
    }
    
    private func setupVisitorView() {
        // 替换根视图
        visitorView = VisitorView()
        
        
        view = visitorView
        
        //登陆注册的按钮监听方法
        visitorView?.registerButton.addTarget(self, action: "visitorViewDidRegister", forControlEvents: UIControlEvents.TouchUpInside)
        
        visitorView?.loginButton.addTarget(self, action: "visitorViewDidLogin", forControlEvents: UIControlEvents.TouchUpInside)
        
        //设置导航栏的按钮
        navigationItem.leftBarButtonItem = UIBarButtonItem(title: "注册", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewDidRegister")
        
        navigationItem.rightBarButtonItem = UIBarButtonItem(title: "登陆", style: UIBarButtonItemStyle.Plain, target: self, action: "visitorViewDidLogin")
        
    }

}









